package edu.gyc.objecthomework; /**

File name: YearsToDensity.java

This program does the following:
Reads in the name, population, and growth rate of a species,
an area in square miles, and a target density.
Calculates the number of years it will take the species to
reach the target density or prints a message that it will
never reach the target density.

Uses SpeciesWithDensity class.

Preconditions:
none.

Postconditions:
Displays either the number of years it takes for the species to
reach the target density or a message that it will never
reach the target density.

Author: Lew Rakocy
email address: Lrakocy@devrycols.edu
Date: 8/26/00
Last changed:
Updated for fourth edition by Brian Durney, November 2004

*/
import java.util.*;

public class YearsToDensity
{
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);

        SpeciesWithDensity s1 = new SpeciesWithDensity();

        // read in species information
        s1.readInput();

        // read in area
        System.out.println("Enter the area (in square miles): ");
        double area = keyboard.nextDouble();

        //read in target density
        System.out.println("Enter target density: ");
        double targetDensity = keyboard.nextDouble();

        // special condition detection:
        // What if it is already above the target density?

        if(s1.density(area) >= targetDensity)
        {
            System.out.println();
            System.out.println
                ("Density for " + s1.getName() + " is already "
                 + targetDensity + " or more per square mile.");
        }

        else
        {
            // Find number of years it takes the species to
            // reach the target density.
            int years = 1;
            while(s1.projectedPopulation(years)/area < targetDensity)
            {
                years = years + 1;
            }
            System.out.println("Species " + s1.getName()
                               + " will reach " + targetDensity
                               + " per square mile in " + years + " years.");
        }
    }
}

